home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 746 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.7 KB  |  75 lines

  1. Newsgroups: comp.std.c
  2. Path: phcoms4.seri.philips.nl!panther!baynes
  3. From: baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes)
  4. Subject: Re: It this portable?
  5. Sender: news@ukpsshp1.serigate.philips.nl (account for localnews)
  6. Message-ID: <Dpw78E.3GE@ukpsshp1.serigate.philips.nl>
  7. Date: Mon, 15 Apr 1996 07:24:12 GMT
  8. References: <Dpp1tv.4Kq@ukpsshp1.serigate.philips.nl> <4kj9gn$6rm@engnews1.Eng.Sun.COM> <4kmurb$f3a@usenet.pa.dec.com>
  9. Organization: Philips Semiconductors, Southampton, UK
  10. X-Newsreader: TIN [version 1.2 PL2]
  11.  
  12. Norman Diamond (diamond@tbj.dec.com) wrote:
  13. : In article <4kj9gn$6rm@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM (Steve Clamage) writes:
  14.    [Note - Steve Clamage's follow up has not made it to my site - was it on a
  15.     restricted distribution, or just lost on the way?]
  16. : >In article 4Kq@ukpsshp1.serigate.philips.nl, baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes:
  17. : >>Is this program [conforming to all possible conforming implementations]
  18. : >>or is it going to give undefined behaviour?
  19. : >>  #include <stdio.h>
  20. : >>  #include <limits.h>
  21. : >>  int main( void )
  22. : >>  {
  23. : >>      printf( "%d", UINT_MAX );
  24. : >>      return 0;
  25. : >>  }
  26. : >>My vote is for undefined, but can anyone construct an argument based on
  27. : >>the represention of integers that makes it implmentation defined?
  28.  
  29. : >The example passes an unsigned int to printf and tells printf to
  30. : >interpret the value as a signed int.
  31.  
  32. : Exactly.  It does not say to convert the unsigned int.  Actually, not
  33. : quite exactly.  Although an implementation storing type tags would be
  34. : contrary to the traditional spirit of C, it would not violate the
  35. : standard.  The example tells such an implementation to check whether
  36. : the standard's rules gave the expression UINT_MAX the type int.
  37.  
  38. : >The Standard's section on types says that signed int and unsigned int
  39. : >have the same size (including sign information) and alignment, and a
  40. : >footnote clarifies the intention to allow interchangeability as
  41. : >function parameters and return values.
  42.  
  43. : Exactly.  The standard makes some rules that don't really accomplish
  44. : much but which provide encouragement for implementations to provide some
  45. : nice extensions.  The footnote clarifies that the committee's intention
  46. : was to encourage implementations to provide some nice extensions.  And
  47. : if I'm not mistaken, the committee already responded to a defect report
  48. : by reaffirming that their intention was to encourage implementations to
  49. : provide some nice extensions, but that implementations are not forced to
  50. : provide this interchangeability.
  51.  
  52. Here is another reason why I think it is undefined. If there are holes
  53. in the integers used by the implementation, there is nothing to say that
  54. they must be in the same place in signed ints and unsigned ints. 
  55.  
  56. Also is there anything to require that the holes even have to be the same size?
  57. In other words do signed int and unsigned int even have to use the same number
  58. of bits for data? (It makes a bit of a mockery of the integral conversions if
  59. they do not.) Some time ago, somewhere else I remember seeing a discusion on
  60. implementing C on a sign-and-magnitude architecture where for unsigned numbers
  61. used the same format as signed ones but just ignored the sign bit. This would
  62. make UINT_MAX < INT_MAX. (Actually in this case the example problem code would
  63. work!) This implementation was regarded as acceptable then is it now?
  64.  
  65. Just to clarify the format:
  66.     signed int   <1 bit sign> < n bits magnatude>
  67.   unsigned int   <1 bit hole> < n bits value>
  68.  
  69. --
  70. Stephen Baynes                              baynes@ukpsshp1.serigate.philips.nl
  71. Philips Semiconductors Ltd
  72. Southampton                                 My views are my own.
  73. United Kingdom
  74.  Are you using ISO8859-1? Do you see ⌐ as copyright, ≈ as division and ╜ as 1/2?
  75.